package satir.player;

import java.util.ArrayList;

import satir.card.MagicToolCard;
import satir.card.RoleCard;
import satir.cell.ActionCell;

/**
 * The Class Player.
 * @version 3.0 April 2012
 * @author Creative Family
 */
public class Player {

    /** The name. */
    private String name;

    /** The figure. */
    private char figure;

    /** The role. */
    private RoleCard role;

    /** The self esteem. */
    private int selfEsteem;

    /** The current cell. */
    private ActionCell currentCell;

    /** The mt cards. */
    private ArrayList<MagicToolCard> mtCards;

    /**
     * Instantiates a new player.
     */
    public Player() {
	name = "default";
	selfEsteem = 5;
	mtCards = new ArrayList<MagicToolCard>();
    }

    /**
     * Instantiates a new player.
     * @param name
     *            the name
     * @param figure
     *            the figure
     * @param currentCell
     *            the current cell
     */
    public Player(final String name, final char figure, final ActionCell currentCell) {
	this.name = name;
	this.figure = figure;
	this.currentCell = currentCell;
	this.currentCell.addPlayer(this);
	selfEsteem = 5;
	mtCards = new ArrayList<MagicToolCard>();
    }

    /**
     * Sets the role.
     * @param role
     *            the new role
     */
    public void setRole(final RoleCard role) {
	this.role = role;
    }

    /**
     * Gets the role.
     * @return the role
     */
    public RoleCard getRole() {
	return role;
    }

    /**
     * Sets the name.
     * @param name
     *            the new name
     */
    public void setName(final String name) {
	this.name = name;
    }

    /**
     * Gets the name.
     * @return the name
     */
    public String getName() {
	return name;
    }

    /**
     * Sets the figure.
     * @param figure
     *            the new figure
     */
    public void setFigure(final char figure) {
	this.figure = figure;
    }

    /**
     * Gets the figure.
     * @return the figure
     */
    public char getFigure() {
	return figure;
    }

    /**
     * Adds the movement.
     * @param addMovement
     *            the add movement
     */
    public void addMovement(final int addMovement) {
	currentCell.removePlayer(this);
	for (int i = 0; i < addMovement; i++) {
	    currentCell = currentCell.getNextCell();
	}
	currentCell.addPlayer(this);

    }

    /**
     * Sets the current cell.
     * @param currentCell
     *            the new current cell
     */
    public void setCurrentCell(final ActionCell currentCell) {
	this.currentCell = currentCell;
    }

    /**
     * Gets the current cell.
     * @return the current cell
     */
    public ActionCell getCurrentCell() {
	return currentCell;
    }

    /**
     * Increase self esteem.
     * @param increaseValue
     *            the increase value
     */
    public void increaseSelfEsteem(final int increaseValue) {
	selfEsteem += increaseValue;
    }

    /**
     * Decrease self esteem.
     * @param decreaseValue
     *            the decrease value
     */
    public void decreaseSelfEsteem(final int decreaseValue) {
	selfEsteem -= decreaseValue;
    }

    /**
     * Sets the self esteem.
     * @param selfEsteem
     *            the new self esteem
     */
    public void setSelfEsteem(final int selfEsteem) {
	if (selfEsteem < 0 || selfEsteem > 10) {
	    this.selfEsteem = 0;
	} else {
	    this.selfEsteem = selfEsteem;
	}
    }

    /**
     * Gets the self esteem.
     * @return the self esteem
     */
    public int getSelfEsteem() {
	return selfEsteem;
    }

    /**
     * Roll dice.
     */
    public void rollDice() {
	throw new UnsupportedOperationException();
    }

    /**
     * Move.
     * @param step
     *            the step
     * @return the integer
     */
    public int move(final int step) {
	throw new UnsupportedOperationException();
    }

    /**
     * Use tool.
     */
    public void useTool() {
	throw new UnsupportedOperationException();
    }

    /**
     * Sets the magic tool cards.
     * @param mtCard
     *            the new magic tool cards
     */
    public void setMtCards(final MagicToolCard mtCard) {
	this.mtCards.add(mtCard);
    }

    /**
     * Removes the magic tool card.
     * @param mtCard
     *            the magic tool card
     */
    public void removeMtCard(final MagicToolCard mtCard) {
	this.mtCards.remove(mtCard);
    }

    /**
     * Gets the magic tool cards.
     * @return the magic tool cards
     */
    public ArrayList<MagicToolCard> getMtCards() {
	return this.mtCards;
    }

    /**
     * Checks if is win.
     * @return true, if is win
     */
    public boolean isWin() {
	return (selfEsteem >= 10);
    }
}
